{"componentChunkName":"component---node-modules-gatsby-theme-chronoblog-src-templates-post-js","path":"/2021-12-26-nginx-server/","result":{"data":{"mdx":{"id":"d7cbfd54-418c-5c28-8aa8-8522ea263d70","excerpt":"Our Node app is running on the Docker container we created in the last  post . Let's add an Nginx Web Server to our Droplet, so that we can…","frontmatter":{"title":"Setting up a Web Server with Nginx","date":"2021-12-26T00:00:00.000Z","description":"We will set up a web server on DigitalOcean Droplet with Nginx","tags":["Nginx","DigitalOcean","Droplet","Web Server"],"cover":{"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAAMABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAABAAGCP/EABQBAQAAAAAAAAAAAAAAAAAAAAL/2gAMAwEAAhADEAAAAeiA6A5A58l//8QAGBABAQEBAQAAAAAAAAAAAAAABAEDAhD/2gAIAQEAAQUCOi5BxZWlCjpVJnJhtxNfP//EABYRAAMAAAAAAAAAAAAAAAAAABARIf/aAAgBAwEBPwGsf//EABYRAAMAAAAAAAAAAAAAAAAAABARIf/aAAgBAgEBPwGsf//EACMQAAEDAwIHAAAAAAAAAAAAAAEAAgMREjEhIwQTIkFRcYH/2gAIAQEABj8Ca8btG1tDriUZOWY9cDuuJuptTGPp+ZUdSXaZcqFePS//xAAeEAABBQACAwAAAAAAAAAAAAABABEhMUFRcYGRof/aAAgBAQABPyF7L4CANupkJhl7Px4QEpKYgArbOQnUEBI6DnM2LQAwD0L/2gAMAwEAAgADAAAAEP8Az//EABgRAQADAQAAAAAAAAAAAAAAAAEAESFR/9oACAEDAQE/EEobzkJ//8QAFxEAAwEAAAAAAAAAAAAAAAAAEBEhUf/aAAgBAgEBPxBUcwf/xAAcEAEBAAIDAQEAAAAAAAAAAAABEQAhMUFRYaH/2gAIAQEAAT8QdmpZkFoBLq3nL9Soup0GDXHDYi6xz7g6AzYnPa0k7yrHRSvvn5gksSdS8b6fMGa3sEP3Wf/Z","aspectRatio":1.7142857142857142,"src":"/static/857bae867cb6351c15a296e47f3e5c6b/3e61c/cover.jpg","srcSet":"/static/857bae867cb6351c15a296e47f3e5c6b/7fcb3/cover.jpg 192w,\n/static/857bae867cb6351c15a296e47f3e5c6b/42594/cover.jpg 384w,\n/static/857bae867cb6351c15a296e47f3e5c6b/3e61c/cover.jpg 768w,\n/static/857bae867cb6351c15a296e47f3e5c6b/a1eb1/cover.jpg 800w","srcWebp":"/static/857bae867cb6351c15a296e47f3e5c6b/dd090/cover.webp","srcSetWebp":"/static/857bae867cb6351c15a296e47f3e5c6b/ae504/cover.webp 192w,\n/static/857bae867cb6351c15a296e47f3e5c6b/fef30/cover.webp 384w,\n/static/857bae867cb6351c15a296e47f3e5c6b/dd090/cover.webp 768w,\n/static/857bae867cb6351c15a296e47f3e5c6b/b0751/cover.webp 800w","sizes":"(max-width: 768px) 100vw, 768px","presentationWidth":768,"presentationHeight":446},"resize":{"src":"/static/857bae867cb6351c15a296e47f3e5c6b/3e61c/cover.jpg"}}}},"fields":{"slug":"/2021-12-26-nginx-server/"},"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Setting up a Web Server with Nginx\",\n  \"cover\": \"./cover.jpg\",\n  \"date\": \"2021-12-26T00:00:00.000Z\",\n  \"description\": \"We will set up a web server on DigitalOcean Droplet with Nginx\",\n  \"tags\": [\"Nginx\", \"DigitalOcean\", \"Droplet\", \"Web Server\"]\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Our Node app is running on the Docker container we created in the last \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"http://localhost:8000/2021-12-25-nodejs-postgresql-server-digitalocean/\"\n  }, \"post\"), \".\"), mdx(\"p\", null, \"Let's add an Nginx Web Server to our Droplet, so that we can reverse-proxy all traffic to our server.\"), mdx(\"h3\", {\n    \"id\": \"install-nginx\"\n  }, \"Install Nginx\"), mdx(\"p\", null, \"We can connect to our Droplet and install Nginx with the following command:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"$ apt install nginx\\n\")), mdx(\"p\", null, \"When the installation is completed, verify that Nginx is running by typing:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"$ systemctl status nginx\\n\")), mdx(\"p\", null, \"And we should get something similar to:\"), mdx(\"span\", {\n    \"className\": \"gatsby-resp-image-wrapper\",\n    \"style\": {\n      \"position\": \"relative\",\n      \"display\": \"block\",\n      \"marginLeft\": \"auto\",\n      \"marginRight\": \"auto\",\n      \"maxWidth\": \"696px\"\n    }\n  }, \"\\n      \", mdx(\"span\", {\n    parentName: \"span\",\n    \"className\": \"gatsby-resp-image-background-image\",\n    \"style\": {\n      \"paddingBottom\": \"32.68292682926829%\",\n      \"position\": \"relative\",\n      \"bottom\": \"0\",\n      \"left\": \"0\",\n      \"backgroundImage\": \"url('data:image/jpeg;base64,/9j/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAAHABQDASIAAhEBAxEB/8QAFwABAAMAAAAAAAAAAAAAAAAAAAMECP/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHRNgiUV//EABcQAQEBAQAAAAAAAAAAAAAAAAEAAhL/2gAIAQEAAQUCAHnMX//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABkQAAEFAAAAAAAAAAAAAAAAAAABEBEhMf/aAAgBAQAGPwK0kxv/xAAaEAACAgMAAAAAAAAAAAAAAAAAEQEhQWFx/9oACAEBAAE/IZw7DhuiKoR//9oADAMBAAIAAwAAABCLz//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABURAQEAAAAAAAAAAAAAAAAAABEQ/9oACAECAQE/EAn/xAAcEAACAgIDAAAAAAAAAAAAAAABIQARMUFxgeH/2gAIAQEAAT8QB5IFLXBwBVvfs3ALwZ//2Q==')\",\n      \"backgroundSize\": \"cover\",\n      \"display\": \"block\"\n    }\n  }), \"\\n  \", mdx(\"img\", {\n    parentName: \"span\",\n    \"className\": \"gatsby-resp-image-image\",\n    \"alt\": \"nginx is running\",\n    \"title\": \"nginx is running\",\n    \"src\": \"/static/ca28bba043fd836018b1bb7344aeb53a/a4476/nginx.jpg\",\n    \"srcSet\": [\"/static/ca28bba043fd836018b1bb7344aeb53a/bd2b6/nginx.jpg 205w\", \"/static/ca28bba043fd836018b1bb7344aeb53a/ceeba/nginx.jpg 410w\", \"/static/ca28bba043fd836018b1bb7344aeb53a/a4476/nginx.jpg 696w\"],\n    \"sizes\": \"(max-width: 696px) 100vw, 696px\",\n    \"style\": {\n      \"width\": \"100%\",\n      \"height\": \"100%\",\n      \"margin\": \"0\",\n      \"verticalAlign\": \"middle\",\n      \"position\": \"absolute\",\n      \"top\": \"0\",\n      \"left\": \"0\"\n    },\n    \"loading\": \"lazy\"\n  }), \"\\n    \"), mdx(\"h3\", {\n    \"id\": \"server-blocks\"\n  }, \"Server Blocks\"), mdx(\"p\", null, \"We can set up server blocks to set different configurations and host more than one domain from a single server.\"), mdx(\"p\", null, \"For this, we can create new config files (i.e., /etc/nginx/sites-available/your_domain) for our domain or we can use the default file (/etc/nginx/sites-available/default).\"), mdx(\"p\", null, \"We will just modify the default file. So modify it as follows:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"server {\\n  server_name your_domain www.your_domain;\\n\\n  location / {\\n    proxy_pass http://your_domain:port;\\n  }\\n}\\n\\n\")), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"NOTE: If you are creating your own files for your domain, make sure you link them to the \", mdx(\"em\", {\n    parentName: \"strong\"\n  }, \"/etc/nginx/site-enabled\"), \" directory with the following command:\")), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"strong\"\n  }, \"$ ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/\"))), mdx(\"p\", null, \"Test to make sure there's no syntax error in the files by typing:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"$ nginx -t\\n\")), mdx(\"p\", null, \"If everything is good, restart Nginx:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"$ systemctl restart nginx\\n\")), mdx(\"p\", null, \"That's it! Nginx is now running on our Droplet, and it will direct traffic to our domain, where our Node app is running.\"), mdx(\"h3\", {\n    \"id\": \"conclusion\"\n  }, \"Conclusion\"), mdx(\"p\", null, \"We set up Nginx Web Server on our Droplet. In the next post, we will set up SSL with Let's Encrypt.\"));\n}\n;\nMDXContent.isMDXComponent = true;"}},"pageContext":{"id":"d7cbfd54-418c-5c28-8aa8-8522ea263d70"}},"staticQueryHashes":["1961101537","2542493696"]}